package cn.ld.module.ai.controller.admin.knowledge;

import cn.ld.framework.common.pojo.CommonResult;
import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.common.util.object.BeanUtils;
import cn.ld.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentPageInVO;
import cn.ld.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentOutVO;
import cn.ld.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateInVO;
import cn.ld.module.ai.controller.admin.knowledge.vo.segment.AiKnowledgeSegmentUpdateStatusInVO;
import cn.ld.module.ai.dal.entity.knowledge.AiKnowledgeSegmentEntity;
import cn.ld.module.ai.service.knowledge.AiKnowledgeSegmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.ld.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - AI 知识库段落")
@RestController
@RequestMapping("/ai/knowledge/segment")
@Validated
public class AiKnowledgeSegmentController {

    @Resource
    private AiKnowledgeSegmentService segmentService;

    @GetMapping("/page")
    @Operation(summary = "获取段落分页")
    public CommonResult<PageResult<AiKnowledgeSegmentOutVO>> getKnowledgeSegmentPage(@Valid AiKnowledgeSegmentPageInVO pageInVO) {
        PageResult<AiKnowledgeSegmentEntity> pageResult = segmentService.getKnowledgeSegmentPage(pageInVO);
        return success(BeanUtils.toBean(pageResult, AiKnowledgeSegmentOutVO.class));
    }

    @PutMapping("/update")
    @Operation(summary = "更新段落内容")
    public CommonResult<Boolean> updateKnowledgeSegment(@Valid @RequestBody AiKnowledgeSegmentUpdateInVO inVO) {
        segmentService.updateKnowledgeSegment(inVO);
        return success(true);
    }

    @PutMapping("/update-status")
    @Operation(summary = "启禁用段落内容")
    public CommonResult<Boolean> updateKnowledgeSegmentStatus(@Valid @RequestBody AiKnowledgeSegmentUpdateStatusInVO inVO) {
        segmentService.updateKnowledgeSegmentStatus(inVO);
        return success(true);
    }

}
